package com.ruoyi.yijing.service.impl;

import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.yijing.mapper.YjCategoryMapper;
import com.ruoyi.yijing.domain.YjCategory;
import com.ruoyi.yijing.service.IYjCategoryService;

import static com.ruoyi.common.constant.CacheConstants.CACHE_PRE;

/**
 * 占卜问题分类Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-22
 */
@Service
public class YjCategoryServiceImpl implements IYjCategoryService 
{
    @Autowired
    private YjCategoryMapper yjCategoryMapper;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询占卜问题分类
     * 
     * @param id 占卜问题分类主键
     * @return 占卜问题分类
     */
    @Override
    public YjCategory selectYjCategoryById(Long id)
    {
        return yjCategoryMapper.selectYjCategoryById(id);
    }

    /**
     * 查询占卜问题分类列表
     * 
     * @param yjCategory 占卜问题分类
     * @return 占卜问题分类
     */
    @Override
    public List<YjCategory> selectYjCategoryList(YjCategory yjCategory)
    {
        String key = CACHE_PRE + "selectYjCategoryList_Member";
        List<YjCategory> rst = redisCache.getCacheList(key);
        if (rst == null || rst.size()==0){
            rst = yjCategoryMapper.selectYjCategoryList(yjCategory);
            if (rst.size()>0){
                redisCache.setCacheList(key,rst);
                redisCache.expire(key,1, TimeUnit.MINUTES);
            }
        }
        return rst;
    }

    /**
     * 新增占卜问题分类
     * 
     * @param yjCategory 占卜问题分类
     * @return 结果
     */
    @Override
    public int insertYjCategory(YjCategory yjCategory)
    {
        yjCategory.setCreateBy(SecurityUtils.getUsername());
        yjCategory.setCreateTime(new Date());
        return yjCategoryMapper.insertYjCategory(yjCategory);
    }

    /**
     * 修改占卜问题分类
     * 
     * @param yjCategory 占卜问题分类
     * @return 结果
     */
    @Override
    public int updateYjCategory(YjCategory yjCategory)
    {
        yjCategory.setUpdateBy(SecurityUtils.getUsername());
        yjCategory.setUpdateTime(new Date());
        return yjCategoryMapper.updateYjCategory(yjCategory);
    }

    /**
     * 批量删除占卜问题分类
     * 
     * @param ids 需要删除的占卜问题分类主键
     * @return 结果
     */
    @Override
    public int deleteYjCategoryByIds(Long[] ids)
    {
        return yjCategoryMapper.deleteYjCategoryByIds(ids);
    }

    /**
     * 删除占卜问题分类信息
     * 
     * @param id 占卜问题分类主键
     * @return 结果
     */
    @Override
    public int deleteYjCategoryById(Long id)
    {
        return yjCategoryMapper.deleteYjCategoryById(id);
    }
}
